using Alveo.Interfaces.UserCode;
using System;
using System.ComponentModel;
using System.Windows.Media;

namespace Alveo.UserCode
{
	[Description("Gator oscillator Indicator")]
	[Serializable]
	public class Gactor : IndicatorBase
	{
		private readonly Array<double> _lowBuff;

		private readonly Array<double> _upBuff;

		[Category("Settings"), Description("Jaw Period of the Gator Indicator"), DisplayName("Jaw Period")]
		public int JawPeriod
		{
			get;
			set;
		}

		[Category("Settings"), Description("Jaw Shift of the Gator Indicator"), DisplayName("Jaw Shift")]
		public int JawShift
		{
			get;
			set;
		}

		[Category("Settings"), Description("Teeth Period of the Gator Indicator"), DisplayName("Teeth Period")]
		public int TeethPeriod
		{
			get;
			set;
		}

		[Category("Settings"), Description("Teeth Shift of the Gator Indicator"), DisplayName("Teeth Shift")]
		public int TeethShift
		{
			get;
			set;
		}

		[Category("Settings"), Description("Lips Period of the Gator Indicator"), DisplayName("Lips Period")]
		public int LipsPeriod
		{
			get;
			set;
		}

		[Category("Settings"), Description("Lips Shift of the Gator Indicator"), DisplayName("Lips shift")]
		public int LipsShift
		{
			get;
			set;
		}

		[Category("Settings"), Description("Moving Average type on witch Gator will be calculated"), DisplayName("MA Type")]
		public MovingAverageType MAType
		{
			get;
			set;
		}

		[Category("Settings"), Description("Price type on witch Gator will be calculated"), DisplayName("Price Type")]
		public PriceConstants PriceType
		{
			get;
			set;
		}

		public Gactor()
		{
			base.indicator_buffers = 2;
			base.indicator_chart_window = false;
			base.indicator_color1 = Colors.Green;
			base.indicator_color2 = Colors.Red;
			base.SetIndexLabel(0, "Up");
			base.SetIndexLabel(1, "Down");
			base.IndicatorShortName("Gactor");
			this.JawPeriod = 13;
			this.JawShift = 8;
			this.TeethPeriod = 8;
			this.TeethShift = 5;
			this.LipsPeriod = 5;
			this.LipsShift = 3;
			this.MAType = MovingAverageType.MODE_SMA;
			this.PriceType = PriceConstants.PRICE_MEDIAN;
			this._upBuff = new Array<double>();
			this._lowBuff = new Array<double>();
		}

		protected override int Init()
		{
			base.SetIndexStyle(0, 2, -1, -1, null);
			base.SetIndexStyle(1, 2, -1, -1, null);
			base.SetIndexBuffer(0, this._upBuff, false);
			base.SetIndexBuffer(1, this._lowBuff, false);
			return 0;
		}

		protected override int Start()
		{
			int i = base.Bars - base.IndicatorCounted();
			bool flag = i >= base.Bars;
			if (flag)
			{
				i = base.Bars - 1;
			}
			int num = Math.Max(this.JawPeriod + this.JawShift, this.TeethPeriod + this.TeethShift);
			int num2 = Math.Max(this.TeethPeriod + this.TeethShift, this.LipsPeriod + this.LipsPeriod);
			int num3 = base.Bars - num;
			int num4 = base.Bars - num2;
			while (i >= 0)
			{
				double num5 = base.iAlligator(base.Symbol, base.TimeFrame, this.JawPeriod, this.JawShift, this.TeethPeriod, this.TeethShift, this.LipsPeriod, this.LipsShift, (int)this.MAType, (int)this.PriceType, 1, i);
				double num6 = base.iAlligator(base.Symbol, base.TimeFrame, this.JawPeriod, this.JawShift, this.TeethPeriod, this.TeethShift, this.LipsPeriod, this.LipsShift, (int)this.MAType, (int)this.PriceType, 2, i);
				double num7 = base.iAlligator(base.Symbol, base.TimeFrame, this.JawPeriod, this.JawShift, this.TeethPeriod, this.TeethShift, this.LipsPeriod, this.LipsShift, (int)this.MAType, (int)this.PriceType, 3, i);
				bool flag2 = i <= num3;
				if (flag2)
				{
					double num8 = num6 - num5;
					bool flag3 = num8 < 0.0;
					if (flag3)
					{
						num8 *= -1.0;
					}
					this._upBuff[i, true] = num8;
				}
				bool flag4 = i <= num4;
				if (flag4)
				{
					double num8 = num6 - num7;
					bool flag5 = num8 > 0.0;
					if (flag5)
					{
						num8 *= -1.0;
					}
					this._lowBuff[i, true] = num8;
				}
				i--;
			}
			return 0;
		}

		public override bool IsSameParameters(params object[] values)
		{
			bool flag = values.Length != 10;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = (values[0] != null && base.Symbol == null) || (values[0] == null && base.Symbol != null);
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = values[0] != null && (!(values[0] is string) || (string)values[0] != base.Symbol);
					if (flag3)
					{
						result = false;
					}
					else
					{
						bool flag4 = !(values[1] is int) || (int)values[1] != base.TimeFrame;
						if (flag4)
						{
							result = false;
						}
						else
						{
							bool flag5 = !(values[2] is int) || (int)values[2] != this.JawPeriod;
							if (flag5)
							{
								result = false;
							}
							else
							{
								bool flag6 = !(values[3] is int) || (int)values[3] != this.JawShift;
								if (flag6)
								{
									result = false;
								}
								else
								{
									bool flag7 = !(values[4] is int) || (int)values[4] != this.TeethPeriod;
									if (flag7)
									{
										result = false;
									}
									else
									{
										bool flag8 = !(values[5] is int) || (int)values[5] != this.TeethShift;
										if (flag8)
										{
											result = false;
										}
										else
										{
											bool flag9 = !(values[6] is int) || (int)values[6] != this.LipsPeriod;
											if (flag9)
											{
												result = false;
											}
											else
											{
												bool flag10 = !(values[7] is int) || (int)values[7] != this.LipsShift;
												if (flag10)
												{
													result = false;
												}
												else
												{
													bool flag11 = !(values[8] is MovingAverageType) || (MovingAverageType)values[8] != this.MAType;
													if (flag11)
													{
														result = false;
													}
													else
													{
														bool flag12 = !(values[9] is PriceConstants) || (PriceConstants)values[9] != this.PriceType;
														result = !flag12;
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			return result;
		}
	}
}
